package com.sc.nft.dao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.ShareProfitPanel;
import com.sc.nft.enums.MarketLevelEnum;
import com.sc.nft.mapper.ShareProfitPanelMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_share_profit_panel)数据DAO
 *
 * @author zxy
 * @since 2023-12-09 15:58:57
 * @description 商户banner
 */
@Slf4j
@Repository
public class ShareProfitPanelDao extends ServiceImpl<ShareProfitPanelMapper, ShareProfitPanel> {

    public ShareProfitPanel getByPanelName(String panelName){
        return lambdaQuery().eq(ShareProfitPanel::getPanelName,panelName).one();
    }

    public Page<ShareProfitPanel> panelPage(String panelName, MarketLevelEnum marketLevel, Boolean status, Page page){
        LambdaQueryWrapper<ShareProfitPanel> wrapper = Wrappers.lambdaQuery();
        wrapper.like(StrUtil.isNotBlank(panelName),ShareProfitPanel::getPanelName,panelName);
        wrapper.eq(status!=null,ShareProfitPanel::getStatus,status);
        wrapper.eq(marketLevel!=null,ShareProfitPanel::getMarketLevel,marketLevel);
        wrapper.orderByDesc(ShareProfitPanel::getId);
        return page(page,wrapper);
    }

    public List<ShareProfitPanel> findList(String panelName, MarketLevelEnum marketLevel){
        LambdaQueryWrapper<ShareProfitPanel> wrapper = Wrappers.lambdaQuery();
        wrapper.like(StrUtil.isNotBlank(panelName),ShareProfitPanel::getPanelName,panelName);
        wrapper.eq(ShareProfitPanel::getMarketLevel,marketLevel);
        wrapper.eq(ShareProfitPanel::getStatus,true);
        wrapper.orderByDesc(ShareProfitPanel::getId);
        return list(wrapper);
    }
}